<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="订单时间(美国):" prop="created_at.value">
                            <el-input v-model="queryParams.created_at.value" placeholder="请输入订单时间(美国)" clearable />
                        </el-form-item>
                    </el-col> -->
                    <el-col :md="5" :sm="12">
                        <el-form-item label="email:" prop="email.value">
                            <el-input v-model="queryParams.email.value" placeholder="email" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="物流单号:" prop="tracking_number.value">
                            <el-input v-model="queryParams.tracking_number.value" placeholder="请输入物流单号" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="5" :sm="12">
                        <el-form-item label="客户姓名:" prop="shipping_name.value">
                            <el-input v-model="queryParams.shipping_name.value" placeholder=" 客户姓名" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="5" :sm="12">
                        <el-form-item label="订单编号:" prop="name.value">
                            <el-input v-model="queryParams.name.value" placeholder=" 订单编号" clearable />
                        </el-form-item>
                    </el-col>
                    
                    <el-col :md="6" :sm="12">
                        <el-form-item label="订单日期:" prop="create_at.value">
                            <el-date-picker
                                v-model="queryParams.create_at.value"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    

                    <el-col :md="5" :sm="12">
                        <el-form-item label="sku:" prop="sku.value">
                            <el-input v-model="queryParams.sku.value" placeholder="sku" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="5" :sm="12">
                        <el-form-item label="反馈详情:" prop="qids.value">
                                <el-cascader
                                    v-model="queryParams.qids.value"
                                    :options="options"
                                    :props="props"
                                    collapse-tags
                                    clearable>
                                </el-cascader>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :md="6" :sm="12">
                        <el-form-item label="标记时间:" prop="mark_time.value">
                            <el-date-picker
                                v-model="queryParams.mark_time.value"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col> -->

                    <el-col :md="4" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>

            
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>
            <el-drawer
                title="统计"
                :visible.sync="drawer"
                :direction="direction"
                :before-close="handleClose">
                <p>总共 ：{{ tableData2_count }}</p>
                    <el-table
                        :data="tableData2"
                        :loading="loading2"
                        style="width: 100%">
                        <el-table-column
                            prop="sku"
                            label="SKU"
                            width="180">
                        </el-table-column>
                        <el-table-column
                            prop="ttitle"
                            label="问题分类"
                            width="180">
                        </el-table-column>
                        <el-table-column
                            prop="dtitle"
                            label="问题详情">
                        </el-table-column>
                        <el-table-column
                            prop="count"
                            label="数量">
                        </el-table-column>
                    </el-table>
            </el-drawer>
            
                
            <!-- 列表 -->
            <el-tabs v-model="activeTab" @tab-click="handleStatus" type="border-card">
                <el-tab-pane v-for="(item, index) in qustype" :key="index" :label="item.label" :name="item.value.toString()">
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="240" align="left">
                        <template slot-scope="scope">
                            <!-- <el-button class="btn-mar" size="mini" type="primary" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button> -->
                            <el-button class="btn-mar" size="mini" type="info" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button>
                            <!-- <el-button class="btn-mar" size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button> -->

                        </template>
                    </el-table-column>
                </template>
            </qa-table>
            </el-tab-pane>
            </el-tabs>
            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? '编辑' : '详情'" :visible="editOpen"  :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData"  :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>

    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    
    data() {
        return {
            drawer: false,
            direction: 'rtl',
            tableData2: [],
            // table结构
            columns: [
                // {
                //     visible: true,
                //     label: 'id',
                //     prop: 'id',
                // },
                {
                    visible: true,
                    label: '邮箱',
                    prop: 'email',
                },

                {
                    visible: true,
                    label: '客户姓名',
                    prop: 'shipping_name',
                },
                {
                    visible: true,
                    label: '物流单号',
                    prop: 'tracking_number',
                },
                {
                    visible: true,
                    label: '订单编号',
                    prop: 'name',
                },

                {
                    visible: true,
                    label: 'sku',
                    prop: 'sku',
                },

                {
                    visible: true,
                    label: '变体信息',
                    prop: 'variant_title',
                },
              
                {
                    visible: true,
                    label: '问题详情',
                    prop: 'qustiontype',
                },
                {
                    visible: true,
                    label: '订单时间(美国)',
                    prop: 'created_at',
                },
                {
                    visible: true,
                    label: '标记时间',
                    prop: 'mark_time',
                },

            ],
            // 接口地址
            api: {
                index: `/admin/markorder/index`,
                find: `/admin/markorder/find`,
                add: `/admin/markorder/add`,
                edit: `/admin/markorder/edit`,
                delete: `/admin/markorder/delete`,
                export: `/admin/markorder/export`,
                status: `/admin/markorder/status`
            },
            editFormParams: {
            },
            pageInfo: {
                sort: 'id',
            },
            primaryKey: 'id',
            // 搜索表单是否展开
            searchExpand: false,
              //是否展示搜索
            showSearch: true,
            // 查询参数
            queryParams: {
                created_at: { value:undefined, op: '='},
                email: { value:undefined, op: '%like%'},
                sku: { value:undefined, op: '%like%'},
                qids: { value:undefined, op: '%like%'},
                shipping_name: { value:undefined, op: '%like%'},
                name: { value:undefined, op: '%like%'},
                mark_time: { value:[], op: 'range'},
                tid: { value: undefined, op: '=' },
                create_at: { value: [], op: 'range' },
                tracking_number: { value: undefined, op: '%like%' }
            },
            activeTab: '',
            // props: { multiple: true },
        }
    },
    created () {
        this.initIndex()
        this.count_qusnum()
    },
    watch: {
        
    },
    methods: {
        handleClose(done) {
            this.drawer = false
            // this.$confirm('确认关闭？')
            // .then(_ => {
            //     done();
            // })
            // .catch(_ => {});
        },
        // 搜索
        submitSearch() {
            this.pageInfo.page = 1
            this.initIndex()
            this.count_qusnum()
        },
        // 案列：当前组件格式化方法
        testFormatter(prop) {
            return prop
        },
        handleStatus(tab) {
            this.queryParams.tid.value = tab.name
            this.submitSearch()
        },
        
        // sku生成回显
        async count_qusnum() {
            this.loading2 = true;
            let response = await this.request.post('/admin/markorder/count_qusnum', { 
                tid : this.queryParams.tid.value,
                sku : this.queryParams.sku.value,
                created_at : this.queryParams.create_at.value,
                qids : this.queryParams.qids.value,
            })
            this.loading2 = false;
            if(this.queryParams.qids.value.length == 0){
                
            }else{
                this.drawer = true;
            }
            this.tableData2 = response.data.list;
            this.tableData2_count = response.data.count;
        },
        
    }
}
</script>
<style lang="scss">
.btn-mar {
    margin: 5px !important;
}
</style>
